package com.returnsoft.resource.service;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import com.returnsoft.resource.dto.CandidateStateDto;
import com.returnsoft.resource.eao.CandidateStateEao;
import com.returnsoft.resource.entity.CandidateState;
import com.returnsoft.resource.exception.ConversionExcepcion;
import com.returnsoft.resource.exception.EaoExcepcion;
import com.returnsoft.resource.exception.RecruitmentException;
import com.returnsoft.resource.util.Conversion;

/**
 * Session Bean implementation class CandidateStateBean
 */
@Stateless
@LocalBean
public class CandidateStateBean implements CandidateStateInterface {
	
	@EJB
	private CandidateStateEao eao;
	@EJB
	private Conversion conv;
	

    /**
     * Default constructor. 
     */
    public CandidateStateBean() {
        // TODO Auto-generated constructor stub
    }
    
    @Override
	public List<CandidateStateDto> findAll() throws RecruitmentException {
		try {
			List<CandidateState> entities = eao.findAll();
			List<CandidateStateDto> dtos = new ArrayList<CandidateStateDto>();
			for (CandidateState entity : entities) {
				CandidateStateDto dto = conv.fromCandidateState(entity);
				dtos.add(dto);
			}
			return dtos;
		} catch (EaoExcepcion e) {
			throw new RecruitmentException(e.getMessage());
		} catch (ConversionExcepcion e) {
			throw new RecruitmentException(e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			throw new RecruitmentException(e.getMessage());
		}
	}
    
    @Override
   	public List<CandidateStateDto> findActiveList() throws RecruitmentException {
   		try {
   			List<CandidateState> entities = eao.findEnablesList();
   			List<CandidateStateDto> dtos = new ArrayList<CandidateStateDto>();
   			for (CandidateState entity : entities) {
   				CandidateStateDto dto = conv.fromCandidateState(entity);
   				dtos.add(dto);
   			}
   			return dtos;
   		} catch (EaoExcepcion e) {
   			throw new RecruitmentException(e.getMessage());
   		} catch (ConversionExcepcion e) {
   			throw new RecruitmentException(e.getMessage());
   		} catch (Exception e) {
   			e.printStackTrace();
   			throw new RecruitmentException(e.getMessage());
   		}
   	}
    
    /*@Override
   	public List<CandidateStateDto> findInterviewList() throws RecruitmentException {
   		try {
   			List<CandidateState> entities = eao.findInterviewList();
   			List<CandidateStateDto> dtos = new ArrayList<CandidateStateDto>();
   			for (CandidateState entity : entities) {
   				CandidateStateDto dto = conv.fromCandidateState(entity);
   				dtos.add(dto);
   			}
   			return dtos;
   		} catch (EaoExcepcion e) {
   			throw new RecruitmentException(e.getMessage());
   		} catch (ConversionExcepcion e) {
   			throw new RecruitmentException(e.getMessage());
   		} catch (Exception e) {
   			e.printStackTrace();
   			throw new RecruitmentException(e.getMessage());
   		}
   	}*/

	@Override
	public CandidateStateDto findById(Integer stateId)
			throws RecruitmentException {
		try {
			CandidateState state = eao.findById(stateId);
			CandidateStateDto stateDto = conv.fromCandidateState(state);
			
			return stateDto;
			
		} catch (EaoExcepcion e) {
   			throw new RecruitmentException(e.getMessage());
   		} catch (ConversionExcepcion e) {
   			throw new RecruitmentException(e.getMessage());
   		} catch (Exception e) {
   			e.printStackTrace();
   			throw new RecruitmentException(e.getMessage());
   		}
		
	}
    
    

}
